package com.jfinalbbs.module.caruser;

import com.alibaba.druid.support.logging.Log;
import com.jfinal.aop.Before;
import com.jfinal.aop.Clear;
import com.jfinal.plugin.activerecord.Page;
import com.jfinalbbs.common.BaseController;
import com.jfinalbbs.common.Constants;
import com.jfinalbbs.interceptor.UserInterceptor;
import com.jfinalbbs.module.user.User;
import com.jfinalbbs.utils.DateUtil;
import com.jfinalbbs.utils.ext.route.ControllerBind;
import com.xiaoleilu.hutool.http.HttpUtil;
import com.xiaoleilu.hutool.util.CharsetUtil;

import java.util.Date;
import java.util.List;
import java.util.ListIterator;

/**
 * Created by Tomoya. Copyright (c) 2016, All Rights Reserved.
 * http://jfinalbbs.com
 */
@ControllerBind(controllerKey = "/caruser")
@Clear
public class CaruserController extends BaseController {

	@Clear
	public void existsiji() {
		System.out.println("进入existsiji");

		String nameValsj = getPara(0);
		boolean c = Caruser.me.existsiji(nameValsj);
		System.out.println(c);
		success(c);
	}

	@Clear
	public void existservice() {
		System.out.println("进入existservice");

		String nameValSERVICE = getPara(0);
		boolean c = Serviceuser.me.existservice(nameValSERVICE);
		System.out.println(c);
		success(c);
	}

	@Clear
	public void addsiji() {
		System.out.println("进入addsiji");
		// loginname,password,realname,phone
		String loginname = HttpUtil.decode(getPara(0), CharsetUtil.UTF_8);
		String password = HttpUtil.decode(getPara(1), CharsetUtil.UTF_8);
		String realname = HttpUtil.decode(getPara(2), CharsetUtil.UTF_8);
		String phone = HttpUtil.decode(getPara(3), CharsetUtil.UTF_8);

		boolean c = Caruser.me.addsiji(loginname, password, realname, phone);
		System.out.println(c);
		success(c);
	}

	@Clear
	public void addservice() {
		System.out.println("进入addservice");
		// loginname,password,realname,phone
		String loginname = HttpUtil.decode(getPara(0), CharsetUtil.UTF_8);
		String password = HttpUtil.decode(getPara(1), CharsetUtil.UTF_8);
		String realname = HttpUtil.decode(getPara(2), CharsetUtil.UTF_8);
		String phone = HttpUtil.decode(getPara(3), CharsetUtil.UTF_8);

		boolean c = Serviceuser.me.addservice(loginname, password, realname, phone);
		System.out.println(c);
		success(c);
	}

	@Clear
	public void loginsj() {
		System.out.println("进入loginsj");
		// nameVal, passwordVal
		String nameVal = HttpUtil.decode(getPara(0), CharsetUtil.UTF_8);
		String passwordVal = HttpUtil.decode(getPara(1), CharsetUtil.UTF_8);

		Caruser c = Caruser.me.loginsj(nameVal, passwordVal);
		System.out.println(c);
		success(c);
	}

	@Clear

	public void loginservice() {
		System.out.println("进入Serviceuser");
		// nameVal, passwordVal
		String nameVal = getPara(0);
		String passwordVal = getPara(1);

		Serviceuser c = Serviceuser.me.loginservice(nameVal, passwordVal);
		System.out.println(c);
		success(c);
	}

	@Clear
	public void get4slist() {
		System.out.println("进入get4slist");
		// nameVal, passwordVal
		Integer currentPage = getParaToInt("currentPage");
		Integer pagesize = getParaToInt("pagesize");
		Page<Baoyang> c = Baoyang.me.get4slist(currentPage, pagesize);
		success(c);
	}

	@Clear
	public void getbaoxiulist() {
		System.out.println("进入getbaoxiulist");
		// nameVal, passwordVal
		String myid = HttpUtil.decode(getPara(0), CharsetUtil.UTF_8);
		Integer currentPage = getParaToInt("currentPage");
		Integer pagesize = getParaToInt("pagesize");

		Page<Repair> c = Repair.me.getbaoxiulist(myid, currentPage, pagesize);
		success(c);
		// renderJson(c);
	}

	@Clear

	public void getjiedanlist() {
		System.out.println("进入getjiedanlist");
		// nameVal, passwordVal
		// String myid = getPara(0);

		List<Repair> c = Repair.me.getjiedanlist();
		success(c);
	}

	@Clear
	public void add4s() {
		// fbr, typeme, content INSERT INTO baoyang
		// (faburen,fabutime,type,content) VALUES(
		System.out.println("进入add4s");
		// nameVal, passwordVal
		String fbr = getPara(0);
		String typeme = HttpUtil.decode(getPara(1), CharsetUtil.UTF_8);
		String content = HttpUtil.decode(getPara(2), CharsetUtil.UTF_8);

		String creattime = com.xiaoleilu.hutool.util.DateUtil.now();

		boolean c = Baoyang.me.add4s(fbr, creattime, typeme, content);
		success(c);
	}

	@Clear
	public void jiedan() {
		// servicename, danziid
		// (faburen,fabutime,type,content) VALUES(
		System.out.println("进入jiedan");
		// nameVal, passwordVal
		String servicename = HttpUtil.decode(getPara(0), CharsetUtil.UTF_8);
		String danziid = getPara(1);

		String creattime = com.xiaoleilu.hutool.util.DateUtil.now();

		boolean c = Repair.me.jiedan(servicename, danziid, "已接单");
		success(c);
	}

	@Clear
	public void addbaoxiu() {
		// sijiid, carrealname, carphone, cph, gpszbx, gpszby, gpsw
		System.out.println("进入addbaoxiu");
		// nameVal, passwordVal
		String sijiid = HttpUtil.decode(getPara(0), CharsetUtil.UTF_8);
		String carrealname = HttpUtil.decode(getPara(1), CharsetUtil.UTF_8);
		String carphone = getPara(2);
		String cph = getPara(3);
		String gpsw = getPara(4);
		String gpszbx = getPara("gpszbx");
		String gpszby = getPara("gpszby");

		String gpszb = gpszbx + "," + gpszby;
		System.out.println(gpszb);
		String creattime = com.xiaoleilu.hutool.util.DateUtil.now();

		boolean c = Repair.me.addbaoxiu(sijiid, carrealname, carphone, cph, creattime, gpszb,
				HttpUtil.decode(gpsw, CharsetUtil.UTF_8), "未接单");

		success(c);
	}

}
